<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * MY_Library adds error management functions to libraries
 * 
 * @author Casey McLaughlin
 * @package CIHeadStart
 * @link http://code.google.com/p/ciheadstart
 */
class MY_Library
{
	var $error_log;
	
	/**
	 * Constructor
	 *
	 * @access public
	 * @return MY_Model
	 */
	function MY_Library()
	{
		$this->error_log = array();
	}

	// --------------------------------------------------------------------		

	/**
	 * Return an array containing all errors record during
	 * the execution of the code in the library.
	 * 
	 * Returns an empty array if no errors exist
	 *
	 * @access public
	 * @return array
	 */
	function get_errors()
	{
		return $this->error_log;
	}

	// --------------------------------------------------------------------	
	
	/**
	 * Returns the last error recroding during the execution of
	 * the code in the library.  Returns "(no errors)" string if no
	 * errors exist
	 *
	 * @access public
	 * @return string
	 */
	function get_last_error()
	{
		if (count($this->error_log) < 1)
			return "(no errors)";
		else
			return $this->error_log[(count($this->error_log)-1)];
	}
	
	// --------------------------------------------------------------------			
	
	/**
	 * Adds an error to the errors array in the current library.
	 * 
	 * @access private
	 * @param string $error_value
	 * @return boolean Always FALSE
	 */
	function _record_error($error_value)
	{
		$this->error_log[] = $error_value;
	}

	// --------------------------------------------------------------------			
	
	/**
	 * Adds an error to the errors array in the current library and
	 * returns FALSE so that a function can return false and record the
	 * error at the same time.  Ex:
	 * 
	 *   if (something_bad_happened())
	 * 		return _do_error("Something just hit the fan!";
	 * 
	 * @access private
	 * @param string $error_value
	 * @return boolean Always FALSE
	 */
	function _do_error($error_value)
	{
		$this->_record_error($error_value);
		return FALSE;
	}
}
	
/* End of file RCP_Library.php */
/* Location: ./app/libraries/RCP_Library.php */